namespace EntLibEC.View.Cmn
{
    using System;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Collections;

    using EntLibEC.Cmn;
    using EntLibEC.Info.Basic;
    using EntLibEC.Biz.Basic;

    /// <summary>
    ///		Summary description for Category.
    /// </summary>
    public partial class Category : System.Web.UI.UserControl
    {

        private CategoryManager cm = CategoryManager.GetInstance();

        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
        }

        public void BindCategory()
        {
            BindC1();
            BindC2();
            BindC3();
        }
        private void BindC1()
        {
            ddlC1.Items.Clear();
            SortedList sl = cm.GetC1List();
            if (sl != null && sl.Count != 0)
            {
                foreach (Category1Info item in sl.Keys)
                {
                    ddlC1.Items.Add(
                        new ListItem(item.ToString(), item.SysNo.ToString()));
                }
            }
            ddlC1.Items.Insert(0, new ListItem(AppConst.AllSelectString, AppConst.IntNull.ToString()));
        }
        private void BindC2()
        {
            ddlC2.Items.Clear();
            int c1Sysno = Convert.ToInt32(ddlC1.SelectedItem.Value);
            SortedList sl = cm.GetC2List();
            if (sl != null && sl.Count != 0)
            {
                foreach (Category2Info item in sl.Keys)
                {
                    if (c1Sysno == AppConst.IntNull || item.C1SysNo == c1Sysno)
                        ddlC2.Items.Add(
                            new ListItem(item.ToString(), item.SysNo.ToString()));
                }
            }
            ddlC2.Items.Insert(0, new ListItem(AppConst.AllSelectString, AppConst.IntNull.ToString()));
        }
        private void BindC3()
        {
            ddlC3.Items.Clear();
            int c2Sysno = Convert.ToInt32(ddlC2.SelectedItem.Value);
            SortedList sl = cm.GetC3List();
            if (sl != null && sl.Count != 0)
            {
                foreach (Category3Info item in sl.Keys)
                {
                    if (c2Sysno == AppConst.IntNull || item.C2SysNo == c2Sysno)
                        ddlC3.Items.Add(
                            new ListItem(item.ToString(), item.SysNo.ToString()));
                }
            }
            ddlC3.Items.Insert(0, new ListItem(AppConst.AllSelectString, AppConst.IntNull.ToString()));
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {

        }
        #endregion

        protected void ddlC1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BindC2();
            BindC3();
        }

        protected void ddlC2_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BindC3();
        }

        public int C1SysNo
        {
            get
            {
                return Convert.ToInt32(ddlC1.SelectedItem.Value);
            }
            set
            {
                BindC1();
                ddlC1.SelectedIndex = ddlC1.Items.IndexOf(ddlC1.Items.FindByValue(value.ToString()));
            }
        }
        public int C2SysNo
        {
            get
            {
                return Convert.ToInt32(ddlC2.SelectedItem.Value);
            }
            set
            {
                Category1Info category1 = cm.GetCategory1ByC2SysNo(value);
                if (category1 != null) C1SysNo = category1.SysNo;
                BindC2();
                ddlC2.SelectedIndex = ddlC2.Items.IndexOf(ddlC2.Items.FindByValue(value.ToString()));
            }
        }
        public int C3SysNo
        {
            get
            {
                return Convert.ToInt32(ddlC3.SelectedItem.Value);
            }
            set
            {
                Category2Info category2 = cm.GetCategory2ByC3SysNo(value);
                if (category2 != null) C2SysNo = category2.SysNo;
                BindC3();
                ddlC3.SelectedIndex = ddlC3.Items.IndexOf(ddlC3.Items.FindByValue(value.ToString()));
            }
        }
    }
}
